import requests

import config
from config import URL


class ProductApi(object):
    def __init__(self):
        self.category_url = URL + "/api/v1/category/all"
        self.by_category_url = URL + "/api/v1/product/by_category"
        self.product_url = URL + "/api/v1/product/{}"

    def get_category(self):
        """
        获取商品的所有种类
        :return: 调用商品分类信息的响应
        """
        resp = requests.get(self.category_url)
        return resp

    def get_by_category(self, category_id):
        """
        获取某种商品的信息
        :return:
        """
        resp = requests.get(self.by_category_url, params=category_id)
        return resp

    def get_product(self, product_id):
        resp = requests.get(self.product_url.format(product_id))
        return resp
